#ifndef __CACHEMANAGER__HH__
#define __CACHEMANAGER__HH__

#include "LRUCache.hh"
#include <vector>
#include <map>
#include <set>
#include <thread>
#include <mutex>

using std::vector;
using std::set;
using std::thread;
using std::mutex;

class CacheManager
{
public:
    static CacheManager* createCacheManager();
    static void destoryCacheManager();
    vector<LRUCache>& getCaches();
    set<thread::id>& getPidSet();
    vector<thread::id>& getPidVec();
    LRUCache& getManager();
    vector<mutex>& getLocks();
    void update();
private:
    CacheManager();
    
    vector<LRUCache> _caches;   // 用与查询的缓存
    vector<LRUCache> _swapCache; // 用与交换的缓存
    LRUCache _manager;

    set<thread::id> _p_id_set;   // 线程id必然不同，根据id的大小排序
    vector<thread::id> _p_id_vec;    // 从小到大，使用对应序号的缓存

    vector<mutex> _locks;   // 每个锁, 锁对应一个缓存
    static CacheManager* _instance;
};

#endif